home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#10 (Jul 86)
/
window demo source
/
wind.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-06-09
|
4KB
|
191 lines
/* window manager demonstration
* base on program in
* Using Macintosh Toolbox with C
* page 70
*/
/* Here are our include files */
#include "abc.h" /* Our own defines */
#include "Events.h" /* also includes Macdefs.h */
#include "Window.h" /* also includes Quickdraw.h, which
in turn requires M68KLIB.D */
/* Here are our defines */
#define Screen QD->screenBits.bounds
#define charCodeMask 0x000000FF
/* Here are our Global variables */
WindowPtr theWindow;
WindowRecord windowRec;
Rect dragbound;
Rect limitRect;
main()
{
InitWindows();
InitCursor();
FlushEvents(everyEvent);
/* Initialize our global variables */
theWindow = Nil; /*indicates no window */
SetRect(&dragbound,
Screen.left + 4,
Screen.top + 24,
Screen.right - 4,
Screen.bottom - 4);
SetRect(&limitRect,60,40,
Screen.right - Screen.left - 4,
Screen.bottom - Screen.top - 24);
dowindow(); /* make new window */
eventloop(); /* check for events */
}
dowindow()
{
char *title; /* first title for window */
Rect boundsRect;
if (not theWindow) /* if no window exists, make one */
{
title = "ABC Window";
SetRect(&boundsRect,50,50,300,150);
theWindow = NewWindow(windowRec, &boundsRect,
CtoPstr(title),True,documentProc,
(WindowPtr) -1, True, 0);
DrawGrowIcon(theWindow);
PtoCstr(title);
}
}
eventloop()
{
EventRecord theEvent;
while(True)
if (GetNextEvent(everyEvent,&theEvent))
switch(theEvent.what)
{ /* only check key and */
case keyDown: /* mouse down events */
dokey(&theEvent);
break;
case mouseDown:
domouse(&theEvent);
break;
default:
break;
}
}
dokey(er)
EventRecord *er;
{
char c; /* character from message */
char *title2; /* second title for window */
if (not(er->modifiers & cmdKey)) /* only pay attention to cmd keys */
return; /* if command key is down */
c = er->message & charCodeMask; /* extract character, lower 8 bits */
if (c equals 'q' or c equals 'Q') /* 'q' quits program */
ExitToShell();
if (not theWindow)
{
if (c equals 'm' or c equals 'M')
{
dowindow();
return;
}
else
{
SysBeep(1);
return;
}
}
/* Have a window, so try commands */
switch (c)
{
case 'x':
case 'X':
CloseWindow(theWindow);
theWindow = Nil;
break;
case 's':
case 'S':
ShowWindow(theWindow);
DrawGrowIcon(theWindow);
break;
case 'h':
case 'H':
HideWindow(theWindow);
break;
case 't':
case 'T':
title2 = "A Different Title";
SetWTitle(theWindow, CtoPstr(title2));
PtoCstr(title2);
break;
default:
SysBeep(1);
break;
}
}
domouse(er)
EventRecord *er;
{
short windowcode;
WindowPtr whichWindow;
short ingo;
long size;
windowcode = FindWindow(&er->where, &whichWindow);
switch (windowcode)
{
case inDesk:
if (theWindow notequal 0)
{
HiliteWindow(theWindow, False);
DrawGrowIcon(theWindow);
}
else
ExitToShell(); /* allow an exit if no window */
break;
case inMenuBar:
SysBeep(1);
break;
case inSysWindow:
SysBeep(1);
break;
case inContent:
HiliteWindow(whichWindow,True);
DrawGrowIcon(theWindow);
break;
case inDrag:
DragWindow(whichWindow, &er->where, &dragbound);
DrawGrowIcon(theWindow);
break;
case inGrow:
/* not included this month */
break;
case inGoAway:
ingo = TrackGoAway(whichWindow,&er->where);
if (ingo)
{
CloseWindow(whichWindow);
theWindow = Nil;
}
break;
}
}